#include <openssl/sha.h>
#include <string>

#include "cCrypto.h"

void cCrypto::SHA_256(unsigned char* idata, int size, unsigned char* odata) {
	SHA256( idata, size, odata );
}

std::string cCrypto::SHA_256_s(unsigned char* idata, int size) {
	unsigned char odata[32];
	SHA256( idata, size, odata );
	char ret[65];
	int i;
	for( i = 0; i < 32; i++ ) {
		int a = ((odata[i] & 0xf0) >> 4);
		int b = odata[i] & 0x0f;
		ret[i*2] = (char) (a <= 9 ? '0' + a : 'a' + (a-10));
		ret[i*2+1] = (char) (b <= 9 ? '0' + b : 'a' + (b-10));
	}
	ret[i*2] = '\0';
	return std::string (ret);
}
